package com.example.it_game;

import com.vaadin.ui.*;
import com.vaadin.ui.Window.CloseEvent;
/** Component contains a button that allows opening a window. */
public class WindowOpener extends CustomComponent implements Window.CloseListener {
	Window mainwindow; // Reference to main window
	Window mywindow; // The window to be opened
	Button openbutton; // Button for opening the window
	Button closebutton; // A button in the window
	Button okbutton; // A button in the window
	Label explanation; // A descriptive text

public WindowOpener(String label, Window main) {
	mainwindow = main;
// The component contains a button that opens the window.
	
	final VerticalLayout layout = new VerticalLayout();
	/* Create a new window. */
	mywindow = new Window("Game");
	mywindow.setPositionX(400);
	mywindow.setPositionY(100);
	mywindow.setWidth("300");
/* Add the window inside the main window. */
	mainwindow.addWindow(mywindow);
/* Listen for close events for the window. */
	mywindow.addListener(this);
/* Add components in the window. */
	mywindow.addComponent(new Label("Enter your login and password"));
	
	TextField login = new TextField("Login");
	login.setHeight("30");
	login.setWidth("100");

	
	TextField password = new TextField("Password");
	password.setHeight("30");
	password.setWidth("100");
	
	mywindow.addComponent(login);
	mywindow.addComponent(password);
	
	
	closebutton = new Button("Close", this, "closeButtonClick");
	mywindow.addComponent(closebutton);
	okbutton = new Button(" Ok  ", this, "closeButtonClick");
	mywindow.addComponent(okbutton);

	
	setCompositionRoot(layout);
}
/** Handle the clicks for the two buttons. */

public void closeButtonClick(Button.ClickEvent event) {
/* Windows are managed by the application object. */

/* Return to initial state. */
	openbutton.setEnabled(true);
	explanation.setValue("Closed with button");
}
/** In case the window is closed otherwise. */

public void windowClose1(CloseEvent e) {
/* Return to initial state. */
openbutton.setEnabled(true);
explanation.setValue("Closed with window controls");
}
public void windowClose(CloseEvent e) {
	// TODO Auto-generated method stub
	
}
}